import {reqGoodsList} from '../../api/index'

Page({
  data:{
    categoryId:'',
    subCategoryId:'',
    categoryType:'',
    itemList:[],
    categoryL2List:[]
  },
  onLoad(options){
    console.log(options)
    this.setData({
      categoryId:options.category1Id,
      subCategoryId:options.category2Id,
      categoryType:options.categoryType,
    })
    this.getGoodsList()
  },
  async getGoodsList(){
    try {
      const {categoryId,subCategoryId,categoryType} = this.data
      const res = await reqGoodsList({categoryId,subCategoryId,categoryType})
      console.log(res)
      const itemList = res.data.categoryItems.itemList.map(item=>({
          listPicUrl:item.listPicUrl,
          topLogo:item.topLogo,
          preLogo:item.preLogo,
          name:item.name,
          itemTagList:item.itemTagList,
          finalPriceInfoVO:item.finalPriceInfoVO,
          retailPrice:item.retailPrice,
          id:item.id
      }))
      this.setData({
        itemList,
        categoryL2List:res.data.categoryL2List
      })
    } catch (error) {
      console.log(error)
      wx.showToast({
        title: '获取分类失败',
        icon:'error'
      })
    }
  }
})